package com.zds.hj.poseidon.biz.dispatcher.credit;

import cn.hutool.core.bean.BeanUtil;
import com.zds.boot.dispatch.annotation.DispatcherHandler;
import com.zds.boot.dispatch.comm.enums.ModuleNodeTypeEnum;
import com.zds.boot.dispatch.dto.BaseReqModel;
import com.zds.boot.dispatch.dto.BaseResultModel;
import com.zds.boot.dispatch.dto.ModuleBaseInfo;
import com.zds.hj.poseidon.biz.common.helper.ProcessAgreementHandleService;
import com.zds.hj.poseidon.facade.dto.hpp.credit.CreditInfoEntityDto;
import com.zds.hj.product.facade.constant.ApplicationContainerConstant;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author wex
 * @Description 授权协议签章
 * @Date 2023-06-08 15:54
 */
@DispatcherHandler(value = "AuthAgreementSignHandler", desc = "授权协议签章", applicationContainer = ApplicationContainerConstant.FRONT_END, nodeType = ModuleNodeTypeEnum.BUSINESS)
@Slf4j
public class AuthAgreementSignHandler extends CreditCheckAbsHandler{


    @Resource
    private ProcessAgreementHandleService processAgreementHandleService;

    @Override
    public void creditDoExecute(BaseReqModel params, BaseResultModel resultModel, CreditInfoEntityDto reqData, CreditInfoEntityDto dbData) {
        try {
            processAgreementHandleService.agreementSignHandle(dbData);
            BeanUtil.copyProperties(dbData, reqData);
            resultModel.setResult(dbData);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            Map<String, Object> resultMap = new HashMap<>();
            resultMap.put("retrySign", true);
            resultMap.put("curStep", params.getStep());
            resultModel.setResult(resultMap);
            resultModel.setBizNo(params.getBizNo());
            resultModel.setProductId(params.getProductId());
            resultModel.setBlockingEngine(true);
        }
    }


    @Override
    public ModuleBaseInfo moduleBaseInfo() {
        ModuleBaseInfo moduleBaseInfo = super.moduleBaseInfo();
        moduleBaseInfo.setAuto(true);
        moduleBaseInfo.setReverse(true);
        moduleBaseInfo.setAsyn(false);
        return moduleBaseInfo;
    }
}
